﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RayTracer
{
    class Vector
    {
        private double x;
        private double y;
        private double z;
        private double length;

        // CONSTRUCTORS
        public Vector()
        {
            this.x = 0;
            this.y = 0;
            this.z = 0;
            this.length = 0;
        }

        public Vector(double x, double y, double z) 
        {
            this.x = x;
            this.y = y;
            this.z = z;
            this.length = 0;
        }

        // PROPERTIES
        public double X
        {
            get { return this.x; }
            set { x = value; }
        }

        public double Y
        {
            get { return this.y; }
            set { y = value; }
        }

        public double Z
        {
            get { return this.z; }
            set { z = value; }
        }

        public double Length
        {
            get { return Math.Sqrt((this.X * this.X) + (this.Y * this.Y) + (this.Z * this.Z)); }
            set { length = value; }
        }

        // METHODS       
        public Vector Normalize()
        {
            this.length = Math.Sqrt((this.X*this.X)+(this.Y*this.Y)+(this.Z*this.Z));
            double x = this.X / this.length;
            double y = this.Y / this.length;
            double z = this.Z / this.length;
            return new Vector(x, y, z);
        }

        //cross product
        static public Vector CrossProduct(Vector v1, Vector v2)
        {
            //Point3D a = v1.Normalize();
            //Point3D b = v2.Normalize();

            double x = v2.Z * v1.Y - v2.Y * v1.Z;
            double y = v2.X * v1.Z - v2.Z * v1.X;
            double z = v2.Y * v1.X - v2.X * v1.Y;

            Vector v3 = new Vector(x, y, z);

            return v3;
        }

        //dot product
        static public double DotProduct(Vector v1, Vector v2)
        {
            return v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z;
        }


        public static Vector operator *(Vector v, double scalar)
        {
            return new Vector(v.X * scalar, v.Y * scalar, v.Z * scalar);
        }


        public static Vector operator +(Vector v1, Vector v2)
        {
            return new Vector(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);
        }

    }
}
